/**
 * @file Define the merchant controller
 * 
 * @author Steve Gao<gaofu@parllay.com>
 */
const WebBaseController = require('./web-base-controller');

const {SystemServices}  = require('../../constants');

class MerchantController extends WebBaseController {

    get salesService() {
        if (!this._salesService) {
            this._salesService = this.getSystemService(SystemServices.SALES_SERVICE);
        }
        return this._salesService;
    }

    get name() {
        return 'MerchantController';
    }

    get handlersPath() {
        return 'merchant';
    }

    /**
     * Wrap the SalesService's finishPurchase method
     * 
     * @name finishPurchase
     * @param {Object} params - The notify data 
     * @param {String} type - The return type
     * @param {Function} parentCallback - The callback function
     * 
     * @returns {void}
     */
    finishPurchase(params, type, parentCallback) {
        this.salesService.finishPurchase(params, type, (result) => {
            parentCallback(result);
        });
    }

    /**
     * Wrap the SalesService's purchaseProductions method
     * 
     * @name purchaseProductions
     * @param {String} userId - The customer's user id
     * @param {Number} planId - The production's plan id
     * @param {Any} item - The item to purchase 
     * @param {Number} itemCount - The count of purchase
     * @param {Object} params - The additional parameters for the item
     * @param {Function} parentCallback - The callback function 
     * 
     * @returns {void}
     */
    purchaseProductions(userId, planId, item, itemCount, params, parentCallback) {
        this.salesService.purchaseProductions(userId, planId, item, itemCount, params, (result) => {
            parentCallback(result);
        });
    }
}

exports.MerchantController = MerchantController;